package cn.acmenms.listener;

import cn.acmenms.utils.SpringContextUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

/**
 * @ClassName: AcmenMSContextLoaderListener
 * @Description: 继承ContextLoaderListener在Spirng容器初始化时可以进行个性化操作
 * @author: 神奇的鸭鸭
 * @Date: 2017/12/6 13:55
 */
public class AcmenMSContextLoaderListener extends ContextLoaderListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        super.contextInitialized(event);
        // 初始化SpringContextUtil的context
        ServletContext servletContext = event.getServletContext();
        ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        SpringContextUtils.setContext(ctx);

        // TODO 项目初始化要做的事情?

    }
}